Repository navigation
ADD: Unit tests for plot_confusion_matrix with mock CSV data - #15
Merged
Merged
Conversation
Adds tests/test_confusion_matrix.py with five tests covering title, return value, normalization, custom column names, and default-axis behavior. Removes sklearn from conftest mocks (real sklearn is now installed in CI) and adds scikit-learn to the workflow pip install. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds test_confusion_matrix_counts (raw integer counts) and test_normalized_confusion_matrix_values (row-normalized floats). Both extract the plotted image array from ax.images[0] and compare against the expected 3x3 matrix derived from the CSV fixture. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
On headless runners (GitHub Actions Ubuntu), importing matplotlib.pyplot
before setting the backend can raise if no GUI toolkit (Tk, Qt) is
installed, aborting conftest.py before the sys.modules mocks are applied.
Without those mocks lars cannot be imported, causing the patch() call in
mock_openai to fail with ModuleNotFoundError.
Fix: move the sys.modules mock loop to the top of conftest.py, then call
matplotlib.use("Agg") before pyplot is imported anywhere. Also set
MPLBACKEND=Agg in the workflow as a belt-and-suspenders guard.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
scipy's is_torch_array() checks sys.modules['torch'] and calls issubclass(cls, mod.Tensor). With torch mocked as MagicMock, Tensor is a MagicMock instance rather than a class, raising TypeError. lars never imports torch or torchvision, so there is nothing to stub. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit tests for the plot_confusion_matrix function.